package com.cn.service;

import java.io.BufferedReader;  
import java.io.InputStreamReader;  
import java.net.URL;  
import java.net.URLEncoder;  
import java.util.HashMap;  
import java.util.Map;  
public class ShopsService {

	 private static final String BAIDU_APP_KEY = "vRCxUEVlAvGghjo77PlGYphc";
	 private String str;  
     
	    /** 
	     * 调用百度地图区域检索POI服务
	     * @param address 请求的地址
	     * @param lng 请求的经度
	     * @param lat 请求的维度
	     * @return 返回String类型的json该区域的商家信息
	     */  
	    public String getShops(String address,double lng,double lat,int page_num) {  
	        try {  
	            // 将地址转换成utf-8的16进制  
	            address = URLEncoder.encode(address, "UTF-8");  
	            // 如果有代理，要设置代理，没代理可注释  
	            // System.setProperty("http.proxyHost","192.168.172.23");  
	            // System.setProperty("http.proxyPort","3209");  
	            URL resjson = new URL("http://api.map.baidu.com/place/v2/search?&query="+address+"&location="+lng+","+lat+"&radius=2000&output=json&scope=2&page_num="+page_num+"&ak="+BAIDU_APP_KEY);  
	            System.out.println("shopservice page_num:"+page_num);
	            System.out.println("http://api.map.baidu.com/place/v2/search?&query="+address+"&location="+lng+","+lat+"&radius=2000&output=json&scope=2&page_num="+page_num+"&ak="+BAIDU_APP_KEY);
	            BufferedReader in = new BufferedReader(new InputStreamReader(  
	                    resjson.openStream(),"utf-8"));  
	            String res;  
	            StringBuilder sb = new StringBuilder("");  
	            while ((res = in.readLine()) != null) {  
	                sb.append(res.trim());  
	            }  
	            in.close();  
	            str = sb.toString();  
	            //System.out.println("return json:" + str);  
	            
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
	        return str;
	    }  
	  
	    public static void main(String args[]) {  
	       ShopsService shopService = new ShopsService();
	       String ss= shopService.getShops("医院", 31.250159, 121.448568,0);  
	       System.out.println(ss);
 
	    }  

}
